package com.lwb.eduservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lwb.commonutils.Row;
import com.lwb.eduservice.entity.EduChapter;
import com.lwb.eduservice.entity.chapter.ChapterVo;
import com.lwb.eduservice.service.EduChapterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-11-17
 */
@RestController
@RequestMapping("/eduservice/edu-chapter")
public class EduChapterController {

    @Autowired
    private EduChapterService eduChapterService;

    //通过课程id查询章节小节的方法
    @ApiOperation("通过课程id查询章节小节")
    @GetMapping("getChapterVideo/{courseId}")
    public Row getChapterVideo(@PathVariable String courseId){
        List<ChapterVo> list = eduChapterService.getChapterVideoById(courseId);
        return Row.SUCCESS().data("list",list);
    }

    //添加章节
    @PostMapping("addChapter")
    public Row addChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.save(eduChapter);
        return Row.SUCCESS();
    }

    //根据章节id查询
    @GetMapping("getChapterInfo/{chapterId}")
    public Row getChapterInfo(@PathVariable String chapterId){
        EduChapter eduChapter = eduChapterService.getById(chapterId);
        return Row.SUCCESS().data("chapter",eduChapter);
    }

    //修改章节
    @PostMapping("updateChapter")
    public Row updateChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.updateById(eduChapter);
        return Row.SUCCESS();
    }

    //删除章节
    @GetMapping("deleteChapter/{chapterId}")
    public Row deleteChapter(@PathVariable String chapterId){
        boolean flag = eduChapterService.deleteChapterById(chapterId);
        if(flag) {
            return Row.SUCCESS();
        }else{
            return Row.ERROR();
        }
    }
}

